<template>
  <lay-container fluid="true" style="padding: 10px">
    <lay-row :space="10">
      <lay-col :md="24">
        <lay-card>
          <lay-form style="margin-top: 20px">
            <lay-row>
              <lay-col :md="6">
                <lay-form-item label="关键字：" label-width="60">
                  <lay-input
                    v-model="qm.key" style="width: 90%" placeholder="用户姓名、Url"
                    allow-clear="true"
                  ></lay-input>
                </lay-form-item>
              </lay-col>
              <lay-col :md="10">
                <lay-row>
                  <lay-col :md="12">
                    <lay-form-item label="产生日期：" label-width="70">
                      <lay-date-picker v-model="qm.dtb" placeholder="开始日期" allowClear simple ></lay-date-picker>                   
                    </lay-form-item>                    
                  </lay-col>
                  <lay-col :md="12">
                    <lay-form-item label="~" label-width="10">
                      <lay-date-picker v-model="qm.dte" placeholder="截至日期" allowClear simple></lay-date-picker>                   
                    </lay-form-item>      
                  </lay-col>
                </lay-row>
                 
              </lay-col>
              

              <lay-col :md="6">
                <lay-form-item label-width="0">
                  <lay-button type="primary" @click="toSearch">查询</lay-button>
                  <lay-button @click="toReset">重置</lay-button>
                </lay-form-item>
              </lay-col>
            </lay-row>
          </lay-form>
        </lay-card>
      </lay-col>
      <lay-col :md="24">
        <lay-card>
          <lay-table
            id="Id"
            :page="page"
            :columns="columns"
            :dataSource="dataSource"
            :default-toolbar="defaultToolbar" 
            v-model:selectedKey="selectedKey"
            v-model:selectedKeys="selectedKeys"
            :rowClassName="rowClassName"
            
            @row="rowClick"
            @Change="pageChange"
            @sortChange="sortChange"
          >
            <template v-slot:toolbar>
              <lay-row>
                <lay-col :md="18">
                    
                  <!--<lay-button size="sm">删除</lay-button> -->
                </lay-col>
                <lay-col style="text-align:right;">
                   
                   
                  <lay-button prefix-icon="layui-icon-export" suffix-icon=""
                    @click="tableExport"
                    >导出</lay-button>

                </lay-col>
              </lay-row>
              
            </template>
            <template v-slot:ImgUrl="{ data }"> 
              <lay-icon :type="data.ImgUrl"></lay-icon>
            </template>
             
            <template v-slot:operator="{ }">
              
            </template>
           
          </lay-table>
        </lay-card>
      </lay-col>
    </lay-row>
  </lay-container>
</template>

<script lang="ts">
import { ref, watch,reactive,onMounted,h } from 'vue'
import { layer } from '@layui/layer-vue'
import MyHttp from "../../library/MyHttp";  
import MyWin from "../../library/MyWin"; 
import MyPage from "../../library/MyPage"; 
import {MyExcel} from "../../library/MyExcel"; 
import {MySimpleExport,TableColumn} from "../../library/MySimpleExport"; 
 
export default {
  setup() {
    
    const baseUrl="/hterror";
    const baseQUrl=baseUrl+"/page";
    const pageName="系统异常";

    const myWin=ref<any>(null);
    const selectedKey = ref<any>("") 
    const selectedKeys = ref<any>([]) 
    const defaultToolbar = ref(false)
    const page = ref(  new MyPage()  ); 
     
    const columns = [
      
      // {
      //   title: '选择',
      //   width: '50px',
      //   type: 'radio',
      //   fixed: 'left'
      // },
      {
        title: '序号',
        width: '50px' ,
        key: 'rowNo'
      },
      { key:'Host',title: '请求Host', width: '100px', },
{ key:'Url',title: 'Url', width: '100px', },
{ key:'Memo',title: '操作', width: '100px', },
 
{ key:'Pin',title: '参数', width: '100px', },
{ key:'Ex_ClsName',title: '错误类名', width: '100px',
        ellipsisTooltip: true },
{ key:'Ex_Msg',title: '错误信息', width: '100px',   
        ellipsisTooltip: true },
 
{ key:'Name',title: '姓名', width: '100px', },
{ key:'Browser',title: '浏览器', width: '100px', },
{ key:'IP',title: 'IP', width: '100px', },
{ key:'Crt_DT',title: '创建日期', width: '100px', },



 
     
    ]

    const dataSource = ref([]);

    const rowClick = function (data: any) {
      selectedKey.value=data.Id;
    }

    const rowDoubleClick = function (data: any) {}

    const pageChange = function ({ current, limit }: any) {
      if(qm.pageSize!=limit)
      {
        qm.pageSize=limit ;
        qm.page=1;
        query(1); 
      }else{
        query(current)
      }
      

    }
    function toSearch() { 
      query(1);
    }
     
    function toReset() {
      qm.key= '';
      qm.dtb='';
      qm.dte='';       
    }

    const qm=reactive({
      key:"",
      dtb:"",
      dte:"", 
      page: 1,
      pageSize: 10,
      SortFields:"Crt_DT desc"
    }); 
    const query=async (pageIndex:number) =>{
      if(pageIndex){
        page.value.current=pageIndex;
        qm.page=pageIndex;
      }
      var r=await new MyHttp().page(baseQUrl,qm,
        { 
        },
        columns
      ); 
      dataSource.value=r.data.Data;  
      page.value.total=r.data.Total;
    }
     
    const sortChange = (key: any, sort: number) => {
      qm.SortFields=`${key} ${sort}`;
      query(0);
    }
    const tableExport=async()=>{
     
      var cols=columns as Array<TableColumn>;
      new MySimpleExport().exportExcel(
        {
          qm,
          url:baseQUrl,
          name:pageName,
          columns:cols,
          lx:"page"
        }
        );
    }
    
     
    const rowClassName=(row:any, rowIndex:number):string=>{
      if(row.Id==selectedKey.value){ 
        return "";        //RowSelected
      }
      else{
        return "";
      }
    }
    
    onMounted(() =>{  
      myWin.value=new MyWin();
      query(1);
    });
    return {
      columns,
      dataSource,
      selectedKey, 
      selectedKeys,
      defaultToolbar,
      page,
      rowClick,
      rowDoubleClick,
      pageChange,
      toReset,
      toSearch,
       

      qm,
      query,
      
      sortChange,
      tableExport,
    
      myWin,
      rowClassName,

    }
  }
}
</script>
<style  >

 

</style>